const express = require('express');
const router = express.Router();

const { avatar } = require('../controllers/avatar')

const multer  = require('multer')
const {auth} = require("../middleware/auth");
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, './public/images')
    },
    filename: function (req, file, cb) {
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9) + '.' + file.originalname.split('.')[1]
        cb(null, file.fieldname + '-' + uniqueSuffix)
    }
})

const upload = multer({ storage: storage })
// let upload = multer({dest: '../uploads/'}); //设置上传的的图片保存目录


router.post('/', auth, upload.single('singleFile'), avatar)

module.exports = router